/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-12-14 下午1:22 Created by dwzhang
 */
package com.jade.bss.ec.ware;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.*;

/**
 * 商品SKU。一个产品可以对应到多个SKU信息，对应的依据为商品的规格信息，规格包括颜色、尺码等等。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-12-14 下午1:22
 */
@Entity
@Table (name = "BSS_EC_WARE_SKU")
public class WareSku
        implements Serializable
{
    //SKU编号
    @Id
    @GeneratedValue (generator = "BSS_SEQ_EC_WARE_SKU")
    @SequenceGenerator (name = "BSS_SEQ_EC_WARE_SKU", sequenceName = "BSS_SEQ_EC_WARE_SKU")
    private long id;
    //商品所有者类型
    @Column (name = "owner_type", length = 32, nullable = false, updatable = false)
    private String ownerType;
    //商品所有者
    @Column (name = "owner_id", length = 64, nullable = false, updatable = false)
    private String ownerId;
    //商品标识
    @Column (name = "ware_id", nullable = false, updatable = false)
    private long wareId;
    //价格,单位为元
    @Column (name = "price")
    private double price;
    //市场价格,单位为元
    @Column (name = "market_price")
    private double marketPrice;
    //成本价格,单位为元
    @Column (name = "cost_price")
    private double costPrice;
    //库存，单位为个
    @Column (name = "stock_num")
    private long stockNum;
    //外部SKU标识
    @Column (name = "outer_id", length = 64)
    private String outerId;
    //颜色规格ID
    @Column (name = "color_spec")
    private long colorSpec;
    //尺码规格ID
    @Column (name = "size_spec")
    private long sizeSpec;
    //自定义规格ID
    @Column (name = "other_spec")
    private long otherSpec;
    //状态
    @Column (name = "status")
    private int status;
    //创建时间
    @Column (name = "creation_date", nullable = false, updatable = false)
    private Date creationDate;
    //更新时间
    @Column (name = "update_date")
    private Date updateDate;
    //商品属性值
    @ElementCollection (targetClass = String.class, fetch = FetchType.EAGER)
    @CollectionTable (name = "BSS_EC_SKU_ATTR_VALUE", joinColumns = @JoinColumn (name = "sid"))
    @MapKeyColumn (name = "aid")
    @Column (name = "avalue", length = 1024)
    Map<Long, String> attrs;

    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public String getOwnerType()
    {
        return ownerType;
    }

    public void setOwnerType(String ownerType)
    {
        this.ownerType = ownerType;
    }

    public String getOwnerId()
    {
        return ownerId;
    }

    public void setOwnerId(String ownerId)
    {
        this.ownerId = ownerId;
    }

    public long getWareId()
    {
        return wareId;
    }

    public void setWareId(long wareId)
    {
        this.wareId = wareId;
    }

    public double getPrice()
    {
        return price;
    }

    public void setPrice(double price)
    {
        this.price = price;
    }

    public double getMarketPrice()
    {
        return marketPrice;
    }

    public void setMarketPrice(double marketPrice)
    {
        this.marketPrice = marketPrice;
    }

    public double getCostPrice()
    {
        return costPrice;
    }

    public void setCostPrice(double costPrice)
    {
        this.costPrice = costPrice;
    }

    public long getStockNum()
    {
        return stockNum;
    }

    public void setStockNum(long stockNum)
    {
        this.stockNum = stockNum;
    }

    public String getOuterId()
    {
        return outerId;
    }

    public void setOuterId(String outerId)
    {
        this.outerId = outerId;
    }

    public long getColorSpec()
    {
        return colorSpec;
    }

    public void setColorSpec(long colorSpec)
    {
        this.colorSpec = colorSpec;
    }

    public long getSizeSpec()
    {
        return sizeSpec;
    }

    public void setSizeSpec(long sizeSpec)
    {
        this.sizeSpec = sizeSpec;
    }

    public long getOtherSpec()
    {
        return otherSpec;
    }

    public void setOtherSpec(long otherSpec)
    {
        this.otherSpec = otherSpec;
    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public Date getCreationDate()
    {
        return creationDate;
    }

    public void setCreationDate(Date creationDate)
    {
        this.creationDate = creationDate;
    }

    public Date getUpdateDate()
    {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate)
    {
        this.updateDate = updateDate;
    }

    public Map<Long, String> getAttrs()
    {
        return attrs;
    }

    public void setAttrs(Map<Long, String> attrs)
    {
        this.attrs = attrs;
    }

    public void setAttr(long aid, String avalue)
    {
        if (attrs == null) {
            attrs = new HashMap<Long, String>();
        }
        attrs.put(aid, avalue);
    }

    public String getAttr(long aid)
    {
        return null == attrs ? null : attrs.get(aid);
    }
}
